// 引入request.js
import { method } from 'lodash'
import request from './request'

// 封装各种业务请求接口，登录，获取列表，文件上传，权限接口

// 封装登录接口
export function LoginApi(data){
    return request({
        url:"/login",
        method:"POST",
        data
    })
}

// 获取权限菜单接口
export function getMenuApi(){
     return request({
        url:"/menus",
        method:"GET"
     })
}

// 获取用户列表接口
export function getUserListApi (params){
    return request ({
        url:"/users",
        method:"GET",
        params
    })
}
// 添加
export function getUserAdd (data){
    return request ({
        url:"/users",
        method:"POST",
        data
    })
}
//搜索
export function getUserSearchAPI (data){
    return request ({
        url:"/users",
        method:"GET",
        data
    })
}
// 编辑
export function  getuserEdit(id,data) {
   return request ({
       url:`/users/${id}`,
       method:"PUT",
       data
   }) 
}
// 删除
export function  getuserdelete(id) {
   return request ({
       url:`/users/${id}`,
       method:"DELETE"
   }) 
}
// 状态
export function  getuserstate(uId,type) {
   return request ({
       url:`users/${uId}/state/${type}`,
       method:"PUT"
   }) 
}
// 角色
export function  getusersrole(id,rid) {
    return request ({
        url:`users/${id}/role`,
        method:"PUT",
        data:{rid}
    }) 
 }
// 分配角色
export function  getusersroles() {
    return request ({
        url:`roles`,
        method:"GET"
    }) 
 }
//  权限列表
export function  rightAPI(type="list") {
    return request ({
        url:`rights/${type}`,
        method:"GET"
    }) 
 }
//  角色列表
export function  rolesAPI() {
    return request ({
        url:`/roles`,
        method:"GET"
    }) 
 }
//  删除角色
export function  DelRolesApi(id) {
    return request ({
        url:`roles/${id}`,
        method:"DELETE"
    }) 
 }
//  角色添加
export function  addRolesApi(data) {
    return request ({
        url:`roles`,
        method:"POST",
        data
    }) 
 }
//  角色编辑
export function  editRolesApi(id,data) {
    return request ({
        url:`/roles/${id}`,
        method:"PUT",
        data
    }) 
 }
//  权限列表
export function RolelistAPI(type = "list") {
    return request({
      url: `/rights/${type}`,
      method: 'GET',
    })
  }
//  
export function RoletreeAPI(type = "tree") {
    return request({
      url: `/rights/${type}`,
      method: 'GET',
    })
  }
// 删除角色权限接口
export function RoletreedelAPI(roleId,rightId) {
    return request({
      url: `roles/${roleId}/rights/${rightId}`,
      method: 'DELETE',
    })
  }
// 角色授权
export function RoleRightAPI(roleId,rids) {
    return request({
      url: `roles/${roleId}/rights`,
      method: 'POST',
      data:{
        rids
      }
    })
  }
//商品列表   
export function GoodsAPIlist(params) {
    return request({
      url: `/goods/`,
      method: 'GET',
      params
    })
  }

// 删除商品
  export function  DeletegoodsAPI(goods_id) {
    return request ({
        url:`/goods/${goods_id}`,
        method:"DELETE"
    }) 
  }
// 添加商品  
export function  addgoodsAPI(data) {
    return request ({
        url:`/goods`,
        method:"POST",
        data
    }) 
  }
//   商品管理
export function  goodsAPI(params) {
    return request ({
        url:`/categories`,
        method:"GET",
        params
    }) 
  }

// 订单管理  
export function  ordersAPI(params) {
    return request ({
        url:`/orders`,
        method:"GET",
        params
    }) 
  }
  //添加动态静态属性
  export function  getGoodsParams(id,sel="many") {
     return request({
       url:`categories/${id}/attributes`,
       method:"GET",
       params:{
         sel
       }
     }) 
  }
  //分类商品列表
  export function  addcateAPI(params) {
     return request({
       url:`/categories`,
       method:"GET",
       params
     }) 
  }
  //添加分类接口
export function addGoodsCateAPI(data) {
  return request({
    url: `categories`,
    method: 'post',
    data
  })
}
  //分类商品删除
  export function delcateAPI(id) {
     return request({
       url:`/categories/${id}`,
       method:"DELETE"
     }) 
  }
  

  //分类商品修改
  export function editcateAPI(cateId,cat_name) {
     return request({
       url:`/categories/${cateId}`,
       method:"PUT",
       data:{cat_name}
     }) 
  }
  
  // 获取参数列表接口
  export function cateParamsAPI(cateId,sel="many") {
    return request({
      url:`categories/${cateId}/attributes`,
      method:"GET",
      params:{sel}
    }) 
 }
  // 更新参数列表接口
  export function updateParamsValsAPI(cate_id,attrId,data) {
    return request({
      url: `categories/${cate_id}/attributes/${attrId}`,
      method: 'put',
      data
    })
  }
  // 删除参数列表接口
  // export function deleteManParamsAPI(cat_id,attr_id) {
  //   return request({
  //     url: `categories/${cat_id}/attributes/${attr_id}`,
  //     method: 'delete'
  //   })
  // }








  //获取参数列表接口
export function getGoodsParamsAPI(cateId,sel='many') {
  return request({
    url: `categories/${cateId}/attributes`,
    method: 'get',
    params:{sel}
  })
}

  //更新参数值接口

export function updateGoodsParamsValsAPI(cate_id,attrId,data) {
  return request({
    url: `categories/${cate_id}/attributes/${attrId}`,
    method: 'put',
    data
  })
}

//添加动态参数

export function addGoodsManyParamsAPI(cat_id,data) {
  return request({
    url: `categories/${cat_id}/attributes`,
    method: 'POST',
    data
  })
}

//删除分类参数
export function deleteManParamsAPI(cat_id,attr_id) {
  return request({
    url: `categories/${cat_id}/attributes/${attr_id}`,
    method: 'delete'
  })
}

//商品分类列表接口
export function goodsCateListAPI(params) {
  return request({
    url: '/categories',
    method: 'get',
    params
  })
}
// 数据统计 接口
export function getreportsAPI() {
  return request({
    url: 'reports/type/1',
    method: 'get'
  })
}

